<template>
	<view class="container">
		<uni-notice-bar show-icon="true" @click="getMore" single="true" :text="notice.title" background-color="#fc6500" color="#f2f2f2"
		 showGetMore="true">
		</uni-notice-bar>
		<view class="ad-box">
			<navigator url="/pages/objectiveLive/index">
				<view class="ad">
					<image src="/static/img/index/kgzb.jpg" mode=""></image>
				</view>
				<view class="ad-desc">
					<text class="ad-box-desc">名师全程讲解</text>
				</view>
			</navigator>
			<navigator url="/pages/subjectiveLive/index">
				<view class="ad">
					<image src="/static/img/index/zgzb.jpg" mode=""></image>
				</view>
				<view class="ad-desc">
					<text class="ad-box-desc">限时模考 逐题批改</text>
				</view>
			</navigator>

		</view>
		<!-- 分类 -->
		<view class="seckill-section m-t">
			<view class="s-header tese">
				<text>特色课堂</text>

			</view>
			<view class="cate-section">
				<navigator url="/pages/objectiveShorthand/index">
					<view class="cate-item">
						<image src="/static/img/index/fksj.png"></image>
						<text>法考速记</text>
					</view>
				</navigator>
				<navigator url="/pages/subjectiveCase/index">
					<view class="cate-item">
						<image src="/static/img/index/fkal.png"></image>
						<text>法考案例</text>
					</view>
				</navigator>
				<navigator url="/pages/discussMark/index">
					<view class="cate-item">
						<image src="/static/img/index/fkls.png"></image>
						<text>法考论述</text>
					</view>
				</navigator>
				<navigator url="">
					<view class="cate-item">
						<image src="/static/img/index/fkwk.png"></image>
						<text>法考微课</text>
					</view>
				</navigator>

			</view>
		</view>
		<!-- 	<view class="ad-1">
			<image src="/static/temp/ad1.jpg" mode="scaleToFill"></image>
		</view> -->
		<!-- 正在直播 -->
		<view class="ad-1">
			<view class="zhibo-content" v-show="zbj" @click="goLiveDetail">
				<image :src="zbj.picture"></image>
				<view class="right">
					<view class="title">{{zbj.broadcastname}}({{zbj.broadcastflge == '1'?'正在直播':'未开播'}})</view>
					<view class="time">
						<image src="/static/img/index/time.png"></image>
						<view class="teacher">直播时间: {{zbj.startdate}} - {{zbj.enddate}}</view>
						
					</view>
					<view class="teacher">主讲老师: {{zbj.userxm}} 
						<text v-if="zbj.specialprice=='0.00'" class="attr_tag attr_tag-danger">免费</text>
						<text v-if="zbj.buy_flag=='1' && zbj.specialprice!='0.00'" class="attr_tag attr_tag-primary">已购买</text>
					</view>
				</view>
			</view>
		</view>

		<view class="seckill-section m-t">
			<navigator url="/pages/learningPack/index">
				<view class="s-header">
					<!-- <image class="s-img" src="/static/temp/secskill-img.jpg" mode="widthFix"></image> -->
					<text class="tip">课程套餐</text>
					<text class="more">更多</text>
					<!-- <text class="hour timer">07</text>
				<text class="minute timer">13</text>
				<text class="second timer">55</text>
				<text class="yticon icon-you"></text> -->
				</view>
			</navigator>
			<scroll-view class="floor-list" scroll-x>
				<view class="scoll-wrapper">
					<view v-for="(item, index) in xxb" :key="index" class="floor-item" @click="goLearingPackDetail(item)">
						<image :src="item.picture" mode="aspectFill"></image>
						<text class="title clamp">{{item.packagename}}</text>
						<text class="price">￥{{item.packageprice}}</text>

					</view>
				</view>
			</scroll-view>
		</view>
		
		<view class="seckill-section m-t">
			<navigator url="/pages/hotCourses/index">
				<view class="s-header">
					<text class="tip">精品课程</text>
					<text class="more">更多</text>
				</view>
			</navigator>
			<scroll-view class="floor-list" scroll-x>
				<view class="scoll-wrapper">
					<view v-for="(item, index) in kc" :key="index" class="floor-item" @click="goHostCoursesDetail(item)">
						<image :src="item.picture" mode="aspectFill"></image>
						<text class="title clamp">{{item.curriculumname}}</text>
						<text class="price">￥{{item.specialprice}}</text>
					</view>
				</view>
			</scroll-view>
		</view>
		
		
		<!--法考课程-->
		<!-- <navigator url="/pages/learningPack/index">
			<view class="f-header m-t">
				<image src="/static/temp/h1.png"></image>
				<view class="tit-box">
					<text class="tit">法考课程</text>
					<text class="tit2">Boutique Group Buying</text>
				</view>
				<text class="yticon icon-you"></text>
			</view>	
		</navigator>
		<view class="group-section" >
			<swiper class="g-swiper" :duration="500">
				<swiper-item
					class="g-swiper-item"
					v-for="(item, index) in xxb" :key="index"
					v-if="index%2 === 0"
					@click="goLearingPackDetail(item)"
				>
					<view class="g-item left">
						<image :src="item.picture" mode="aspectFill"></image>
						<view class="t-box">
							<text class="title clamp">{{item.packagename}}</text>
							<view class="price-box">
								<text class="price">￥{{item.packageprice}}</text> 
							</view>
						</view>
						            
					</view>
					<view class="g-item right">
						<image :src="xxb[index+1].picture" mode="aspectFill"></image>
						<view class="t-box">
							<text class="title clamp">{{xxb[index+1].packagename}}</text>
							<view class="price-box">
								<text class="price">￥{{xxb[index+1].packageprice}}</text> 
							</view>
							<view class="pro-box">
							</view>
						</view>
					</view>
				</swiper-item>

			</swiper>
		</view> -->


		<!-- 热门课程 -->
		<!-- <navigator url="/pages/hotCourses/index">
			<view class="f-header m-t">
				<image src="/static/temp/h1.png"></image>
				<view class="tit-box">
					<text class="tit">法硕课程</text>
					<text class="tit2">Competitive Products For You</text>
				</view>
				<text class="yticon icon-you"></text>
			</view>
		</navigator>
		<view class="hot-floor">
			<view class="floor-img-box">
				<image class="floor-img" src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1553409398864&di=4a12763adccf229133fb85193b7cc08f&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201703%2F19%2F20170319150032_MNwmn.jpeg"
				 mode="scaleToFill"></image>
			</view>
			<scroll-view class="floor-list" scroll-x>
				<view class="scoll-wrapper">
					<view v-for="(item, index) in kc" :key="index" class="floor-item" @click="goHostCoursesDetail(item)">
						<image :src="item.picture" mode="aspectFill"></image>
						<text class="title clamp">{{item.curriculumname}}</text>
						<text class="price">￥{{item.specialprice}}</text>
					</view>
					<navigator url="/pages/hotCourses/index">
						<view class="more">
							<text>查看全部</text>
							<text>More+</text>
						</view>
					</navigator>
				</view>
			</scroll-view>
		</view> -->

	</view>
</template>

<script>
	import uniNoticeBar from "@/components/uni-notice-bar/uni-notice-bar.vue"

	import indexApi from '@/api/index.js'

	var _this, indexInterVal;
	export default {
		components: {
			uniNoticeBar
		},
		onShow() {
			// // #ifdef APP-PLUS
			// this.OverflowButton.getInstance().show();
			// // #endif
			_this = this;
			console.log("APP进入首页");
			let {
				usercode,
				userxm
			} = uni.getStorageSync('user')
			_this.usercode = usercode
			_this.initData();
			
			indexInterVal = setInterval(function() {
				_this.Index_zbzt();
			}, 5000)
			
		},
		
		onHide() {
			// // #ifdef APP-PLUS
			// this.OverflowButton.getInstance().hide()
			// // #endif

			clearInterval(indexInterVal)
		},
		onPullDownRefresh() {
			console.log('refresh');
			_this.initData()
		},
		data() {
			return {
				grid: [],
				gonggao: [],
				notice: {},
				xxb: [],
				kc: [],
				zbj: {},
				usercode: ''
			}
		},
		onLoad(query) {
			
			//轮询直播
			
		},
		methods: {
			Index_zbzt(){
				indexApi.Index_zbzt({
					id: _this.zbj.broadcastid
				}).then(res => {
					//直播中
					_this.zbj.broadcastflge = ''
					if(null != res.data){
						_this.zbj.broadcastflge = res.data.broadcastflge;
					}
					
				}).catch(err => {
					console.log(err)
					uni.stopPullDownRefresh();
				})
			},
			initData() {
				indexApi.index({
					usercode: _this.usercode
				}).then(res => {
					//公告
					
					_this.gonggao = res.data.gg || []
					_this.notice = _this.gonggao.length > 0 ? _this.gonggao[0] : {}
					//法考课程
					_this.xxb = res.data.xxb || []
					
					//课程
					_this.kc = res.data.kc || []
					
					//直播中
					_this.zbj = res.data.zbj;

					uni.stopPullDownRefresh();
					// console.log(_this.gonggao)
					// console.log(_this.xxb)
					// console.log(_this.kc)
				}).catch(err => {
					console.log(err)
					uni.stopPullDownRefresh();
				})
			},
			goLiveDetail() {
				let {
					broadcastflge,
					broadcastid
				} = _this.zbj
				if (broadcastflge != '1') {
					//未开播
					uni.showToast({
						icon: 'none',
						title: '当前未开播'
					})
					return;
				}
				uni.navigateTo({
					url: `/pages/subjectiveLive/detail?id=${broadcastid}`
				})
			},
			getMore() {
				let {
					id
				} = _this.notice
				if (!id) {
					return
				}
				uni.navigateTo({
					url: `/pages/notice/detail?id=${id}`
				})
			},
			noticeClick(e) {

				// console.log(e)
				// let id = e.currentTarget.dataset.id

				uni.navigateTo({
					url: '/pages/notice/detail?id=' + 1
				})
			},
			goLearingPack(e) {
				uni.navigateTo({
					url: '/pages/learningPack/index'
				})
			},
			goLearingPackDetail(item) {
				let {
					packageid
				} = item
				uni.navigateTo({
					url: `/pages/learningPack/detail?id=${packageid}`
				})
			},
			goHostCoursesDetail(item) {
				let {
					curriculumid
				} = item
				uni.navigateTo({
					url: `/pages/hotCourses/detail?id=${curriculumid}`
				})
			},
			goHostCourses(e) {
				uni.navigateTo({
					url: '/pages/hotCourses/index'
				})
			}
		},

		// #ifndef MP
		// 标题栏input搜索框点击
		onNavigationBarSearchInputClicked: async function(e) {
			this.$api.msg('点击了搜索框');
		},
		//点击导航栏 buttons 时触发
		onNavigationBarButtonTap(e) {
			const index = e.index;
			if (index === 0) {
				// this.$api.msg('点击了扫描');
				uni.navigateTo({
					url: '/pages/notice/index'
				})
			}
		}
		// #endif
	}
</script>

<style lang="scss">
	.ad-box {
		display: flex;
		justify-content: center;
		background: #fff;

		/* margin-top: 10upx; */
		.ad {
			image {
				width: 320upx;
				height: 210upx;
				margin: 4upx 14upx;
				border-radius: 20upx;

			}

		}

		.ad-desc {
			text-align: center;
			font-size: 28upx;
			color: $font-color-dark;
			margin-bottom: 6upx;

		}
	}

	/* #ifdef MP */
	.mp-search-box {
		position: absolute;
		left: 0;
		top: 30upx;
		z-index: 9999;
		width: 100%;
		padding: 0 80upx;

		.ser-input {
			flex: 1;
			height: 56upx;
			line-height: 56upx;
			text-align: center;
			font-size: 28upx;
			color: $font-color-base;
			border-radius: 20px;
			background: rgba(255, 255, 255, .6);
		}
	}

	page {
		.cate-section {
			position: relative;
			z-index: 5;
			border-radius: 16upx 16upx 0 0;
			margin-top: -20upx;
		}

		.carousel-section {
			padding: 0;

			.titleNview-placing {
				padding-top: 0;
				height: 0;
			}

			.carousel {
				.carousel-item {
					padding: 0;
				}
			}

			.swiper-dots {
				left: 45upx;
				bottom: 40upx;
			}
		}
	}

	/* #endif */


	page {
		background: #f5f5f5;
	}

	.m-t {
		margin-top: 16upx;
	}

	/* 头部 轮播图 */
	.carousel-section {
		position: relative;
		padding-top: 10px;

		.titleNview-placing {
			height: var(--status-bar-height);
			padding-top: 44px;
			box-sizing: content-box;
		}

		.titleNview-background {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 426upx;
			transition: .4s;
		}
	}

	.carousel {
		width: 100%;
		height: 350upx;

		.carousel-item {
			width: 100%;
			height: 100%;
			padding: 0 28upx;
			overflow: hidden;
		}

		image {
			width: 100%;
			height: 100%;
			border-radius: 10upx;
		}
	}

	.swiper-dots {
		display: flex;
		position: absolute;
		left: 60upx;
		bottom: 15upx;
		width: 72upx;
		height: 36upx;
		background-image: url();
		background-size: 100% 100%;

		.num {
			width: 36upx;
			height: 36upx;
			border-radius: 50px;
			font-size: 24upx;
			color: #fff;
			text-align: center;
			line-height: 36upx;
		}

		.sign {
			position: absolute;
			top: 0;
			left: 50%;
			line-height: 36upx;
			font-size: 12upx;
			color: #fff;
			transform: translateX(-50%);
		}
	}

	/* 分类 */
	.cate-section {
		display: flex;
		justify-content: space-around;
		align-items: center;
		flex-wrap: wrap;
		padding: 30upx 0upx 0 0;
		background: #fff;

		.cate-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			font-size: $font-sm + 2upx;
			color: $font-color-dark;
		}

		/* 原图标颜色太深,不想改图了,所以加了透明度 */
		image {
			width: 88upx;
			height: 88upx;
			margin-bottom: 14upx;
			border-radius: 50%;
			opacity: .7;
			box-shadow: 4upx 4upx 20upx rgba(250, 67, 106, 0.3);
		}
	}

	.ad-1 {
		width: 100%;
		height: 180upx;
		padding: 10upx 0;
		background: #f3f3f3;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.zhibo-content {
		width: 95%;
		height: 180upx;
		padding: 0px 20upx;
		margin: 0 auto;
		background: #fff;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		border-radius: 80upx;

		>image {
			width: 120upx;
			height: 120upx;
			margin: 10upx;
			border-radius: 50%;
		}

		.right {
			font-size: 26upx;
			margin-left: 15upx;
			line-height: 45upx;
			width: 70%;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: normal;

			.time {
				display: flex;
				justify-content: flex-start;
				align-items: center;

				image {
					width: 26upx;
					height: 26upx;
					margin-right: 10upx;
				}
				
			}
			.attr_tag{
				font-size: $font-sm + 2upx;
				line-height: 50upx;
				color: #fff;
				
				border-radius: 0 30upx 30upx 0 ;
				margin: 0 20upx;
				padding: 0 10upx;
			}
			.attr_tag-danger{
				background-color: #fb4b6c;
			}
			.attr_tag-primary{
				background-color:  #007aff;
			}
		}

	}

	/* 秒杀专区 */
	.seckill-section {
		padding: 4upx 30upx 24upx;
		background: #fff;

		.s-header {
			display: flex;
			align-items: center;
			height: 92upx;
			line-height: 1;

			.s-img {
				width: 140upx;
				height: 30upx;
			}

			.tip {
				font-size: $font-base;
				color: $font-color-light;
				margin: 0 20upx 0 0;
			}

			.more {
				font-size: $font-lg;
				color: $font-color-light;
				flex: 1;
				text-align: right;
			}

			.timer {
				display: inline-block;
				width: 40upx;
				height: 36upx;
				text-align: center;
				line-height: 36upx;
				margin-right: 14upx;
				font-size: $font-sm+2upx;
				color: #fff;
				border-radius: 2px;
				background: rgba(0, 0, 0, .8);
			}

			.icon-you {
				font-size: $font-lg;
				color: $font-color-light;
				flex: 1;
				text-align: right;
			}
		}

		.tese {
			height: 80upx;
			line-height: 40upx;
			font-size: 28upx;
		}


		.floor-list {
			white-space: nowrap;
		}

		.scoll-wrapper {
			display: flex;
			align-items: flex-start;
		}

		.floor-item {
			width: 150upx;
			margin-right: 20upx;
			font-size: $font-sm+2upx;
			color: $font-color-dark;
			line-height: 1.8;

			image {
				width: 150upx;
				height: 150upx;
				border-radius: 6upx;
			}

			.price {
				color: $uni-color-primary;
			}

			.m-price {
				font-size: $font-sm+2upx;
				text-decoration: line-through;
				color: $font-color-light;
				margin-left: 8upx;
			}
		}
		.floor-item1 {
			display:flex;
			padding:30upx 10upx;
			
			width: 100%;
			margin-right: 20upx;
			font-size: $font-sm+2upx;
			color: $font-color-dark;
			line-height: 1.8;
			image {
				width: 160upx;
				height: 160upx;
				border-radius: 6upx;
			}
			.price {
				color: $uni-color-primary;
			}
		
			.m-price {
				font-size: $font-sm+2upx;
				text-decoration: line-through;
				color: $font-color-light;
				margin-left: 8upx;
			}
			.floor-item1-1{
				
				
			}
			.floor-item1-2{
				width: 500upx;
				position: relative;
				padding:5upx 10upx;
					
				.floor-item-price{
					position: absolute;
					bottom: 0;
					width: 100%;
					padding:10upx 10upx;
					
					.m-price{
						position: absolute;
						right: 0;
					}
				}
				
			}
		}
	}

	.f-header {
		display: flex;
		align-items: center;
		height: 140upx;
		padding: 6upx 30upx 8upx;
		background: #fff;

		image {
			flex-shrink: 0;
			width: 80upx;
			height: 80upx;
			margin-right: 20upx;
		}

		.tit-box {
			flex: 1;
			display: flex;
			flex-direction: column;
		}

		.tit {
			font-size: $font-lg +2upx;
			color: #font-color-dark;
			line-height: 1.3;
		}

		.tit2 {
			font-size: $font-sm;
			color: $font-color-light;
		}

		.icon-you {
			font-size: $font-lg +2upx;
			color: $font-color-light;
		}
	}

	/* 团购楼层 */
	.group-section {
		background: #fff;

		.g-swiper {
			height: 650upx;
			padding-bottom: 30upx;
		}

		.g-swiper-item {
			width: 100%;
			padding: 0 30upx;
			display: flex;
		}

		image {
			width: 100%;
			height: 460upx;
			border-radius: 4px;
		}

		.g-item {
			display: flex;
			flex-direction: column;
			overflow: hidden;
		}

		.left {
			flex: 1.2;
			margin-right: 24upx;

			.t-box {
				padding-top: 20upx;
			}
		}

		.right {
			flex: 0.8;
			flex-direction: column-reverse;

			.t-box {
				padding-bottom: 20upx;
			}
		}

		.t-box {
			height: 160upx;
			font-size: $font-base+2upx;
			color: $font-color-dark;
			line-height: 1.6;
		}

		.price {
			color: $uni-color-primary;
		}

		.m-price {
			font-size: $font-sm+2upx;
			text-decoration: line-through;
			color: $font-color-light;
			margin-left: 8upx;
		}

		.pro-box {
			display: flex;
			align-items: center;
			margin-top: 10upx;
			font-size: $font-sm;
			color: $font-base;
			padding-right: 10upx;
		}

		.progress-box {
			flex: 1;
			border-radius: 10px;
			overflow: hidden;
			margin-right: 8upx;
		}
	}

	/* 分类推荐楼层 */
	.hot-floor {
		width: 100%;
		overflow: hidden;
		margin-bottom: 20upx;

		.floor-img-box {
			width: 100%;
			height: 320upx;
			position: relative;

			&:after {
				content: '';
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				height: 100%;
				background: linear-gradient(rgba(255, 255, 255, .06) 30%, #f8f8f8);
			}
		}

		.floor-img {
			width: 100%;
			height: 100%;
		}

		.floor-list {
			white-space: nowrap;
			padding: 20upx;
			padding-right: 50upx;
			border-radius: 6upx;
			margin-top: -140upx;
			margin-left: 30upx;
			background: #fff;
			box-shadow: 1px 1px 5px rgba(0, 0, 0, .2);
			position: relative;
			z-index: 1;
		}

		.scoll-wrapper {
			display: flex;
			align-items: flex-start;
		}

		.floor-item {
			width: 220upx;
			margin-right: 20upx;
			font-size: $font-sm+2upx;
			color: $font-color-dark;
			line-height: 1.8;

			image {
				width: 180upx;
				height: 180upx;
				border-radius: 6upx;
			}

			.price {
				color: $uni-color-primary;
			}

			.m-price {
				font-size: $font-sm+2upx;
				text-decoration: line-through;
				color: $font-color-light;
				margin-left: 8upx;
			}
		}

		.more {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			flex-shrink: 0;
			width: 180upx;
			height: 180upx;
			border-radius: 6upx;
			background: #f3f3f3;
			font-size: $font-base;
			color: $font-color-light;

			text:first-child {
				margin-bottom: 4upx;
			}
		}
	}

	/* 猜你喜欢 */
	.guess-section {
		display: flex;
		flex-wrap: wrap;
		padding: 0 30upx;
		background: #fff;

		.guess-item {
			display: flex;
			flex-direction: column;
			width: 48%;
			padding-bottom: 40upx;

			&:nth-child(2n+1) {
				margin-right: 4%;
			}
		}

		.image-wrapper {
			width: 100%;
			height: 330upx;
			border-radius: 3px;
			overflow: hidden;

			image {
				width: 100%;
				height: 100%;
				opacity: 1;
			}
		}

		.title {
			font-size: $font-lg;
			color: $font-color-dark;
			line-height: 80upx;
		}

		.price {
			font-size: $font-lg;
			color: $uni-color-primary;
			line-height: 1;
		}
	}
</style>
